/**
 * @param {number[]} fruits
 * @return {number}
 */
var totalFruit = function(fruits) {
    let len = fruits.length
    if(len<=2) return len

    let start = 0
    let end = 0
    let queue={}
    let count = 0
    while (end<len){
        if(queue[fruits[end]]){
            queue[fruits[end]] +=1
        }else{
            queue[fruits[end]] = 1
        }

        while(1){
            let queueArr = Object.keys(queue)
            if(queueArr.length<3) break

            queue[fruits[start]] -=1
            if(queue[fruits[start]]==0){
                delete queue[fruits[start]]
            }

            start++
        }

        let num = 0

        for (const key in queue) {
            if (Object.hasOwnProperty.call(queue, key)) {
                const element = queue[key];
                num = num + element
            }
        }

        count = Math.max(num,count)


        end++
    }

    return count
};


queue={
    a:1,
    b:2,
    c:3
}
let queueArr = Object.keys(queue)
console.log(queueArr);